package luccy.registry;

import java.lang.annotation.Annotation;
import java.util.concurrent.ConcurrentHashMap;

import luccy.behavior.Behavior;
import luccy.util.AssertionUtil;
import luccy.util.ClassUtil;

public final class AnnotationRegistry {

	private static final ConcurrentHashMap<Class<? extends Annotation>, Class<? extends Behavior>> behaviors = new ConcurrentHashMap<Class<? extends Annotation>, Class<? extends Behavior>>();

	private AnnotationRegistry() {
	}

	/**
	 * register annotation and its behavior that you want luccy to work with.
	 */
	@SuppressWarnings("unchecked")
	public static void register(Class<? extends Annotation> clazz,
			Class<? extends Behavior> behavior) {
		AssertionUtil.assertNotNull(clazz);
		AssertionUtil.assertNotNull(behavior);
		behaviors.put(clazz, behavior);
	}

	public static Behavior getBehavior(Class<? extends Annotation> clazz) {
		AssertionUtil.assertNotNull(clazz);
		final Class<? extends Behavior> bc = behaviors.get(clazz);
		return (bc != null) ? ClassUtil.newInstance(bc) : null;
	}

}
